package com.itheima.service.impl;

import com.itheima.dao.ISubwayDao;
import com.itheima.dao.impl.SubwayDaoImpl;
import com.itheima.domain.Subway;
import com.itheima.service.ISubwayService;

import java.io.IOException;
import java.util.ArrayList;

public class SubwayServiceImpl implements ISubwayService {

    private ISubwayDao dao = new SubwayDaoImpl();

    @Override
    public ArrayList<Subway> findAll() {
        return dao.findAll();
    }

    @Override
    public void add(Subway subway) throws IOException {
        dao.add(subway);
    }

    @Override
    public boolean exists(String sid) {
        ArrayList<Subway> list = dao.findAll();
        if (list == null || list.size() == 0) {
            return false;
        }
        for (Subway subway : list) {
            if(subway.getSid().equals(sid)){
                return true;
            }
        }
        return false;
    }
}
